package com.dkm.ou.me.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ou.me.domain.User;
import com.dkm.ou.me.persistence.dao.UserQueryDao;
import com.dkm.ou.me.persistence.entity.UserPo;
import com.dkm.ou.me.repository.UserRepository;

/**
 * 对象功能:t_ou_user Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2016-10-27 22:08:42
 */
@Repository
public class UserRepositoryImpl extends AbstractRepository<String, UserPo,User> implements UserRepository{
	  
	@Resource
	private  UserQueryDao userQueryDao;

	public User newInstance() {
		UserPo po = new UserPo();
		User user = SpringHelper.getBean(User.class);
		user.setData(po);
		return user;
	}

	public User newInstance(UserPo po) {
		User user = SpringHelper.getBean(User.class);
		user.setData(po);
		return user;
	} 
	
	@Override
	protected IQueryDao<String, UserPo> getQueryDao() {
		return userQueryDao;
	}

	@Override
	public User getByAccountOrEmail(String userName, String encryptPassword) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userName", userName);
		params.put("encryptPassword", encryptPassword);
		User user = SpringHelper.getBean(User.class);
		UserPo upPo = userQueryDao.getByKey("getByAccountOrEmail", params);
		user.setData(upPo);
		return user;
	}

	@Override
	public String findByPhonByIds(List<String> phones) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("phones", phones);
	    UserPo userPo =  userQueryDao.getByKey("findByPhonByIds", params);
	    return userPo.getId();
	}
	
}
